package com.tencreat.service.pt.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tencreat.common.core.domain.model.ReqIdParam;
import com.tencreat.common.core.domain.model.ReqIdsParam;
import com.tencreat.domain.pt.MallPtCashVoucher;
import com.tencreat.mapper.pt.MallPtCashVoucherMapper;
import com.tencreat.service.pt.IMallPtCashVoucherService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 现金卷Service业务层处理
 *
 * @author tencreat
 * @date 2021-11-08
 */
@Service
public class MallPtCashVoucherServiceImpl extends ServiceImpl<MallPtCashVoucherMapper, MallPtCashVoucher> implements IMallPtCashVoucherService {


    /**
     * 查询现金卷
     *
     * @param id 现金卷ID
     * @return 现金卷
     */
    @Override
    public MallPtCashVoucher selectMallPtCashVoucherById(ReqIdParam id) {
        return baseMapper.selectById(id.getId());
    }

    /**
     * 查询现金卷列表
     *
     * @param mallPtCashVoucher 现金卷
     * @return 现金卷
     */
    @Override
    public List<MallPtCashVoucher> selectMallPtCashVoucherList(MallPtCashVoucher mallPtCashVoucher) {
        return baseMapper.selectList(Wrappers.query(mallPtCashVoucher));
    }

    /**
     * 新增现金卷
     *
     * @param mallPtCashVoucher 现金卷
     * @return 结果
     */
    @Override
    public int insertMallPtCashVoucher(MallPtCashVoucher mallPtCashVoucher) {
        mallPtCashVoucher.setCreateTime(LocalDateTime.now());
        return baseMapper.insert(mallPtCashVoucher);
    }

    /**
     * 修改现金卷
     *
     * @param mallPtCashVoucher 现金卷
     * @return 结果
     */
    @Override
    public int updateMallPtCashVoucher(MallPtCashVoucher mallPtCashVoucher) {
        mallPtCashVoucher.setUpdateTime(LocalDateTime.now());
        return baseMapper.updateById(mallPtCashVoucher);
    }

    /**
     * 批量删除现金卷
     *
     * @param ids 需要删除的现金卷ID
     * @return 结果
     */
    @Override
    public int deleteMallPtCashVoucherByIds(ReqIdsParam ids) {
        return baseMapper.deleteBatchIds(ids.getId());
    }

    /**
     * 删除现金卷信息
     *
     * @param id 现金卷ID
     * @return 结果
     */
    @Override
    public int deleteMallPtCashVoucherById(ReqIdParam id) {
        return baseMapper.deleteById(id.getId());
    }
}
